<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
    <title>JavaScripTools Manual</title>
    <link rel="stylesheet" type="text/css" href="../../css/style.css">
</head>

<body>
<br>
<h1>JavaScripTools Manual</h1>
<h2>Parsers</h2>
<h3>Working with the DateParser</h3>
<p>The 
<a href="../api/class_DateParser.html">DateParser</a>
is a class that can convert strings to dates and dates to strings using
a mask. The mask is a string containing the following charactes:</p>
<table cellspacing="0" border="1">
    <tr>
        <td width="33%">d: Day</td>
        <td width="33%">M: month</td>
        <td width="34%">y: year</td>
    </tr>
    <tr>
        <td>h: 12 hour</td>
        <td>H: 24 hour</td>
        <td>m: minute</td>
    </tr>
    <tr>
        <td>s: second</td>
        <td colspan="2" width="37%">S: millisecond</td>
    </tr>
    <tr>
        <td>a: am / pm</td>
        <td colspan="2" width="37%">A: AM / PM</td>
    </tr>
    <tr>
        <td colspan="3" width="100%">/. -: Separators</td>
    </tr>
</table>
<p>The constructor parameters are: <ul>
<li><code>mask</code>: The mask string (defaults to the JST_DEFAULT_DATE_MASK constant)</li>
<li><code>enforceLength</code>: a flag indicating if parsing requires all fields to have 
the exact length as declared on the mask (defaults to the JST_DEFAULT_ENFORCE_LENGTH constant)</li>
</ul></p>
<p>For more details about customizing those default values, check out
<a href="General_customizing.html">this chapter</a>.</p>
<p>If the mask has to change, just setting it will make no effect. To do so, you must call the
setMask(newMask) method.</p>
<p>Here are some examples (remember that, the JavaScript Date object, the month
starts on 0):</p>
<pre>//The default value for enforceLength is true
var parser = new DateParser("yyyy-MM-dd");
parser.format(new Date(2006, 9, 2)) -> "2006-10-02"
parser.parse("2000-12-31") -> Dec 31, 2000
parser.parse("06-7-3") -> null (enforceLength is enabled)
parser.parse("ABC") -> null

var parser2 = new DateParser("d/M/yy H:m:s");
parser2.format(new Date(2006, 3, 7, 9, 30, 02)) -> "7/3/06 9:30:2"
</pre>
<br><br>
<hr>
<table width="100%">
    <tr>
        <td width="33%" align="left"><b>Previous:</b><br><a href="Parsers_number.html">Working with the NumberParser</a></td>
        <td width="34%" align="center"><a href="index.html">Table of Contents</a></td>
        <td width="33%" align="right"><b>Next:</b><br><a href="Parsers_custom.html">Using the CustomParser</a></td>
    </tr>
</table>

</body>
</html>
